//
//  LJM_Memory_TableViewCell.m
//  wind
//
//  Created by 李金明 on 16/1/20.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "LJM_Memory_TableViewCell.h"
#import "LJM_HotSongs_CollectionViewCell.h"
#import "LJM_HotSong_Model.h"
//collectionfowl的坐标
#define COLLECTIONFOWLEDGE 5//边界
#define COLLECTWIDTH 20
#define COLLECTHEADHEIGHT 20//区头的高度
#define HEADHEIGHT 20//头的高度
#define TOPHEIGHT 30//tableView的头视图的高度

#define TITLELEFT 10//标题距离左侧的距离
#define TITLEWIDTH 240//标题的宽度
#define MOVEWIDTH 60//更多的宽度
@interface LJM_Memory_TableViewCell () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, retain) UICollectionView *collectionV;
@property (nonatomic, retain) UICollectionViewFlowLayout *flowLy;
@end

@implementation LJM_Memory_TableViewCell
- (void)setDataArr:(NSMutableArray *)dataArr
{
    if (_dataArr != dataArr) {
        [_dataArr release];
        _dataArr = [dataArr retain];
    }
    [self.collectionV reloadData];
}
- (void)dealloc
{
    self.delegate = nil;
    [_dataArr release];
    [_flowLy release];
    [_collectionV release];
    [_titleLab release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    return self;
}
- (void)creatView
{
    self.backgroundColor = [UIColor whiteColor];
    [self addHeadView];
    [self addCollectionView];
}
- (void)layoutSubviews
{
    self.flowLy.sectionInset = UIEdgeInsetsMake(COLLECTIONFOWLEDGE + COLLECTIONFOWLEDGE, COLLECTIONFOWLEDGE, COLLECTIONFOWLEDGE, COLLECTIONFOWLEDGE);
    self.flowLy.itemSize = CGSizeMake((self.frame.size.width - COLLECTWIDTH) / 3, (self.frame.size.width - COLLECTWIDTH) / 3 + COLLECTWIDTH);
    self.flowLy.minimumLineSpacing = COLLECTIONFOWLEDGE;
    self.flowLy.minimumInteritemSpacing = COLLECTIONFOWLEDGE;
    self.collectionV.frame = CGRectMake(0, 50, self.frame.size.width, self.frame.size.height);
    self.titleLab.frame = CGRectMake(TITLELEFT, 30, TITLEWIDTH, 20);

}
#pragma 头图片
- (void)addHeadView
{
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.backgroundColor = [UIColor clearColor];
    self.titleLab.textColor = [UIColor blackColor];
    self.titleLab.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:self.titleLab];
    [_titleLab release];
    
}
#pragma 添加collectionView
- (void)addCollectionView
{
    self.flowLy = [[[UICollectionViewFlowLayout alloc] init] autorelease];
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.flowLy];
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    //进制tableView的滑动
    self.collectionV.scrollEnabled = NO;
    self.collectionV.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.collectionV];
    [_collectionV release];
    
    [self.collectionV registerClass:[LJM_HotSongs_CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
}
#pragma collectionView的协议方法
#pragma 个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}
#pragma cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LJM_HotSongs_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (0 != self.dataArr.count) {
        LJM_HotSong_Model *model = [self.dataArr objectAtIndex:indexPath.row];
        [cell.imageV sd_setImageWithURL:[NSURL  URLWithString:model.picUrl] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        cell.titleLab.text = model.name;
        cell.label.text = model.author;
        
    }
    
    return cell;
}
#pragma 点击
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    LJM_HotSong_Model *model = [self.dataArr objectAtIndex:indexPath.row];
    [self.delegate changeMemoryToSong_Root_sub:model];
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
